package co.edu.usbcali.egrapico.vista.tools;

import co.edu.usbcali.egrapico.vista.FrmPrincipal;
import co.edu.usbcali.egrapico.vista.ambient.LabelProgram;
import co.edu.usbcali.egrapico.vista.ambient.PanelMethod;

public class MethodList extends javax.swing.JLabel implements java.io.Serializable, Cloneable {

    private String namePadre;
    private String id;
    private boolean ban = false, ban1 = false;
    PanelMethod frame;

    /**
     * Creates a new instance of ObjectAtList
     */
    public MethodList(String i) {
        id = i;
        frame = new PanelMethod();
        addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent evt) {
                MethodMouseClicked(evt);
            }
        });
        namePadre = "";
    }

    public void setNamePadre(String p) {
        namePadre = p;
    }

    public String getNamePadre() {
        return namePadre;
    }

    public Object Clonacion() {
        try {
            return clone();
        } catch (CloneNotSupportedException e) {
            return null;
        }
    }

    private void MethodMouseClicked(java.awt.event.MouseEvent evt) {
        if (isCreate() == false) {
            Ladicionar();
        } else {
            mostrarPanel();
        }
    }

    public void setID(String i) {
        id = i;
    }

    public String getID() {
        return id;
    }

    public void setVisible(boolean b) {
        frame.setVisible(b);
    }

    public void setSelected(boolean b) {
        try {
            frame.setSelected(b);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    public PanelMethod getFrame() {
        return frame;
    }

    public boolean isAddToDesktop() {
        return ban;
    }

    public void setToDesktop() {
        ban = true;
    }

    public void mostrarPanel() {
        FrmPrincipal.getMethod(id).setVisible(true);
        FrmPrincipal.getMethod(id).setSelected(true);
    }

    public void Ladicionar() {
        FrmPrincipal.getMethod(id).getFrame().setTitle(id + ".Definition");

        if (!FrmPrincipal.getMethod(id).isAddToDesktop()) {
            FrmPrincipal.addElementtoDesKtop(FrmPrincipal.getMethod(id).getFrame());
            FrmPrincipal.getMethod(id).setToDesktop();
        }
        FrmPrincipal.getMethod(id).setVisible(true);
        FrmPrincipal.getMethod(id).setSelected(true);
        ban1 = true;
    }

    public boolean isCreate() {
        return ban1;
    }

    public boolean parsingC(String idO) {
        for (int i = 0; i < frame.getLPane().getComponentCount(); i++) {
            if (frame.getLPane().getComponent(i) instanceof LabelProgram) {
                if (((LabelProgram) frame.getLPane().getComponent(i)).parsingC(idO)) {
                    return true;
                }
            }
        }
        return false;
    }
}